<template>
  <div class="dashboard-container">
    <div>
      <div>
        <el-row>
          <el-col :span="4">
            <span class="name">相册名称：</span>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-input v-model="ruleForm.album_name" placeholder="请输入机构相册名称"></el-input>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4">
            <span class="name">相册所属的类型：</span>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-select @change="clearData" v-model="ruleForm.album_typeid" filterable placeholder="请选择类型">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </el-col>
        </el-row>
        <el-row v-if="ruleForm.album_typeid=='1'">
          <el-col :span="4">
            <span class="name">相册所属的校区：</span>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light">
              <el-select v-model="ruleForm.album_campusid" filterable placeholder="请选择相册所属的校区">
                <el-option v-for="item in ComList" :key="item.id" :label="item.campus_name" :value="item.id">
                </el-option>
              </el-select>
            </div>
          </el-col>
        </el-row>
      </div>
      <div class="el-select" style="width: 500px;">
        <el-button type="primary" class="div-button" @click="search">搜索</el-button>
        <el-button type="primary" class="div-button" @click="reset">重置</el-button>
      </div>
      <el-row style="margin-top: 15px;">
        <el-button type="primary" @click="$router.push({path: '/photoDetail', query: {id: $route.query.id}})"
                   style="padding: 12px 40px;">添加
        </el-button>
      </el-row>
    </div>
    <div>
      <el-main style="margin-top: 15px;padding: 0;" class="img-div">
        <el-table ref="menuTable"
                  style="width: 100%"
                  :data="list"
                  border>
          <el-table-column label="id" align="center">
            <template slot-scope="scope">{{ scope.row.id }}</template>
          </el-table-column>
          <el-table-column label="相册名称" align="center">
            <template slot-scope="scope">{{ scope.row.album_name }}</template>
          </el-table-column>
          <el-table-column label="alt" align="center">
            <template slot-scope="scope">{{ scope.row.album_alt }}</template>
          </el-table-column>
          <el-table-column label="图片链接" align="center">
            <template slot-scope="scope">{{ scope.row.album_jumpurl }}</template>
          </el-table-column>
          <el-table-column label="相册类型" align="center">
            <template slot-scope="scope">{{ scope.row.album_typeid | photoValue }}</template>
          </el-table-column>
          <el-table-column label="相册所属校区" align="center">
            <template slot-scope="scope">{{ scope.row.campus_name }}</template>
          </el-table-column>
          <el-table-column prop="img" align="center" label="缩略图">
            <template slot-scope="scope">
              <img :src="scope.row.album_url" alt="" style="height: 60px; max-width: 100%;">
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleUpdate(scope.$index, scope.row)">编辑
              </el-button>
              <el-button
                size="mini"
                type="text"
                @click="handleDelete(scope.$index, scope.row)">删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
    </div>
    <div class="block block-div">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="ruleForm.page"
                     :page-sizes="[10, 20, 30, 40, 50]" :page-size="ruleForm.page_size"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {campusComList, albumList, albumDel, courseDel} from "@/api/menu";
import {mapGetters} from "vuex";

export default {
  data() {
    return {
      list: [],
      total: null,
      ComList: [],
      ruleForm: {
        album_name: '',
        album_typeid: '',
        album_campusid: '',
        page: 1,
        page_size: 10,
      },
      options: [{
        value: '1',
        label: '校区相册'
      }, {
        value: '2',
        label: 'banner'
      }, {
        value: '3',
        label: '资质相册'
      }],
      value: '',
      input: '',
      currentPage4: 1,
    }
  },
  computed: {
    ...mapGetters([
      'schoolId'
    ]),
  },
  mounted() {
    this.getPhotoList()
  },
  filters: {
    photoValue: function (val) {
      switch (val) {
        case 1:
          return '校区相册';
          break;
        case 2:
          return 'banner';
          break;
        case 3:
          return '资质相册';
          break;
      }
    }
  },
  methods: {
    clearData() {
      this.ruleForm.album_campusid = ''
      if(this.ruleForm.album_typeid=='1'){
        this.getCampusComList()
      }
    },
    /**
     * 获取列表单条信息
     * @param index
     * @param row
     */
    handleUpdate(index, row) {
      this.$router.push({path: '/photoupdated', query: {rowId: row.id, id: this.$route.query.id}});
      console.log(row)
    },
    /**
     * 列表根据类型获取值
     */
    photoValue() {

    },
    /**
     * 公共查询分类校区数据
     */
    getCampusComList() {
      campusComList({citylog_schoolid: this.schoolId}).then(response => {
        console.log(response);
        this.ComList = response.data
      }).catch(e => {
        e
      });
    },
    handleDelete(index, row) {
      this.$confirm('是否要删除该菜单', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        albumDel(row.id).then(response => {
          this.$message({
            message: '删除成功',
            type: 'success',
            duration: 1000
          });
          this.getPhotoList();
        });
      }).catch(e => e);
    },
    handleSizeChange(val) {
      this.ruleForm.page_size = val;
      this.getPhotoList()
    },
    handleCurrentChange(val) {
      this.ruleForm.page = val;
      this.getPhotoList()
    },
    /**
     * 重置
     */
    reset() {
      this.ruleForm = {
        album_name: '',
        album_typeid: '',
        album_campusid: '',
        page: 1,
        page_size: 10,
      }
      this.getPhotoList();
    },
    /**
     * 搜索
     */
    search() {
      this.getPhotoList(this.ruleForm)
    },
    /**
     * 列表
     */
    getPhotoList() {
      albumList(Object.assign(this.ruleForm, {album_schoolid: this.schoolId})).then(response => {
        console.log(response);
        this.list = response.data.data_list;
        this.total = response.data.total;
      }).catch((e) => {
      })
    },
  }
}
</script>

<style scoped>
.name {
  margin-top: 8px;
  margin-bottom: 30px;
  display: inline-block;
}

.img-div /deep/ .cell {
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>

<style lang="scss" scoped>
.block-div {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
}

.el-select:nth-child(2) {
  margin: 0px 10px;
}

.div-button {
  padding: 12px 0;
  width: 30%;
  margin-left: 0px;
}

.div-button:nth-child(2) {
  margin-left: 20px;
}

.dashboard {
  &-container {
    margin: 0 15px;
    padding: 30px;
    background-color: #fff;
  }

  &-text {
    font-size: 16px;
  }
}
</style>
